//
//  WZPersonalController.m
//  ETong
//
//  Created by wanzhao on 15/10/28.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "EFengAndETongAboutController.h"
#import "WZMineCell.h"
#import "WZMineItem.h"
#import "WZGroupItem.h"
#import "CFolderMgr.h"
#import "CContactMgr.h"
#import "CContactModel.h"
#import "WZHelpController.h"
#import "WZUserInfoController.h"
#import "WZUpdateController.h"
#import "WZSettingController.h"
#import "MBProgressHUD+WZ.h"
#import "WZRootViewController.h"
#import "NetWorkShare.h"
#import "UIBarButtonItem+category.h"
#import "WZQuestionController.h"
#import "WZIntroduceController.h"
#import "WZSuggestController.h"
#import "WZAboutController.h"

@interface EFengAndETongAboutController ()<UITableViewDataSource, UITableViewDelegate, WZMineCellDelegate>

@property (nonatomic, strong) UITableView *tableView;
- (WZGroupItem *)addGroupMineItem;
@property (nonatomic, strong) NSMutableArray *sectionItemArray;
@property (nonatomic, strong) CContactModel *curAccount;


@end

@implementation EFengAndETongAboutController

- (void)dealloc
{
    NSLog(@"WZPersonalController dealloc");
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = RGBCOLOR(238, 238, 238);
    
    
    self.navigationItem.title = @"关于";
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, HARDWARE_SCREEN_HEIGHT - 64 - 49) style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = ClearColor;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.scrollEnabled = NO;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    [self.view addSubview:self.tableView];
    
    //读取当前用户信息
    CAccountModel *acc = [[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount];
    self.curAccount = [[[CContactMgr alloc] init] loadContactWithUserCode:acc.userName];
    
    [self setupSection1];
    [self setupSection2];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
        
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    //    [[NSNotificationCenter defaultCenter] postNotificationName:ADDGUESTURE object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //    [[NSNotificationCenter defaultCenter] postNotificationName:REMOVEGUESTURE object:nil];
}

- (void)setupSection1
{
    WZMineItem *item = [WZMineItem mineItemWithTitle:@"系统更新" icon:nil];
    item.isHiddenAccessView = NO;
    item.isHiddenBackView = YES;
    item.destVc = [WZUpdateController class];
    
    WZMineItem *item2 = [WZMineItem mineItemWithTitle:@"产品介绍" icon:nil];
    item2.isHiddenAccessView = NO;
    item2.isHiddenBackView = YES;
    item2.destVc = [WZIntroduceController class];
    
    
    
    WZMineItem *item3 = [WZMineItem mineItemWithTitle:@"问题解答" icon:nil];
    item3.isHiddenAccessView = NO;
    item3.isHiddenBackView = YES;
    item3.destVc = [WZQuestionController class];
    
    WZMineItem *item4 = [WZMineItem mineItemWithTitle:@"意见反馈" icon:nil];
    item4.isHiddenAccessView = NO;
    item4.isHiddenBackView = YES;
    item4.destVc = [WZSuggestController class];
    
    
    WZGroupItem *groupItem = [self addGroupMineItem];
    groupItem.itemArray = @[item,item2,item3,item4];
    
    
}

- (void)setupSection2
{
    WZMineItem *item = [WZMineItem mineItemWithTitle:@"关于我们" icon:nil];
    item.isHiddenAccessView = NO;
    item.isHiddenBackView = YES;
    item.destVc = [WZAboutController class];
    
    WZGroupItem *groupItem = [self addGroupMineItem];
    groupItem.itemArray = @[item];
}


- (NSMutableArray *)sectionItemArray
{
    if (_sectionItemArray == nil) {
        _sectionItemArray = [NSMutableArray array];
    }
    return _sectionItemArray;
}

- (WZGroupItem *)addGroupMineItem
{
    WZGroupItem *item = [WZGroupItem groupMineItem];
    [self.sectionItemArray addObject:item];
    return item;
}

- (NSArray *)sectionArray
{
    return self.sectionItemArray;
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.sectionItemArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return [self.sectionItemArray[section] itemArray].count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSInteger count = [tableView numberOfRowsInSection:indexPath.section];
    
    WZMineCell *cell = [WZMineCell mineCellWithTableView:tableView];
    WZGroupItem *item = self.sectionItemArray[indexPath.section];
    if (count == 1 || indexPath.row == count - 1) {
        cell.line.hidden = YES;
    } else {
        cell.line.hidden = NO;
    }
    cell.item = item.itemArray[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = ClearColor;
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return OppositeHeightRate(15);
    } else {
        return OppositeHeightRate(15);
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return OppositeHeightRate(60);
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    WZGroupItem *groupitem = self.sectionItemArray[indexPath.section];
    WZMineItem *item = groupitem.itemArray[indexPath.row];
    if (item.block != nil) {
        item.block();
    }
    
    if (item.destVc) {
        
        UIViewController *vc = [[item.destVc alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}


@end